package com.hk.elseservice.service.impl;

import com.hk.elseservice.mapper.ContactUsMapper;
import com.hk.elseservice.service.ContactUsService;
import com.hk.model.ContactUs;
import com.hk.utlis.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;


/**
 * @Author: zhe
 * @Date: 2021/6/15 11:37
 * @Statement: 联系我们业务逻辑层
 */
@Service
public class ContactUsServiceImpl implements ContactUsService {

    @Autowired
    ContactUsMapper contactUsMapper;

    @Override
    public List<ContactUs> findAll(Integer page, Integer limit, ContactUs t) {
        List<ContactUs> contactUsList = contactUsMapper.findAll(t);
        return contactUsList;
    }

    @Override
    public int count(Integer page, Integer limit, ContactUs contactUs) {
        int count = contactUsMapper.count(contactUs);
        return count;
    }

    @Override
    public ContactUs findById(Integer id) {
        ContactUs contactUs = contactUsMapper.findById(id);
        return contactUs;
    }

    @Override
    public ContactUs findByState(int i) {
        ContactUs contactUs = contactUsMapper.findByState(i);
        return contactUs;
    }

    @Override
    public int save(ContactUs t) {
        String dateTimeString = DateUtils.dateTimeString(new Date());
        t.setGmtCreate(dateTimeString);
        t.setGmtModified(dateTimeString);
        int save = contactUsMapper.save(t);
        if (save == 1) {
            System.out.println("联系我们信息添加成功！");
        }
        return save;
    }

    @Override
    public int update(ContactUs t) {
        //        修改日期时间
        String dateTimeString = DateUtils.dateTimeString(new Date());
        t.setGmtModified(dateTimeString);
        int update = contactUsMapper.update(t);
        if (update == 1) {
            System.out.println("当前联系我们信息修改成功");
        }
        return update;
    }

    @Transactional
    @Override
    public int updateState(ContactUs t) {
        String dateTimeString = DateUtils.dateTimeString(new Date());
        t.setGmtModified(dateTimeString);
        int i1 = contactUsMapper.updateState1();
        int i = contactUsMapper.updateState(t);
        if (i1 >=1 && i == 1) {
            System.out.println("当前联系我们信息状态修改完成！");
        }
        return i;
    }

    @Override
    public int delete(Integer id) {
        int delete = contactUsMapper.delete(id);
        if (delete == 1) {
            System.out.println("当前公司信息删除成功！");
        }
        return delete;
    }
}
